<template>
  <div id="app" class="disbox">
    <div class="nav">
      <div class="logo color background">
        <img src="../../../static/img/logo.png" />蜂窝帮 Pro
      </div>
      <div class="adminUser disbox">
        <img :src="`https://q2.qlogo.cn/headimg_dl?dst_uin=${adminLink.qq}&spec=100`" class="head" />
        <div class="disflex">
          <h3 class="ell">{{adminLink.name}}</h3>
          <p class="ell" @click="logout">退出</p>
        </div>
        <img src="../../../static/img/icon.png" class="icon" />
      </div>
      <ul class="navList">

        <li>
          <router-link to="/help/" :class="isActive('/help/')?'active':''">
            帮助中心<i class="iconfont icon-shu"></i>
          </router-link>
        </li>
        <li>
          <router-link to="/task/" :class="isActive('/task/')?'active':''">
            任务<b class="num" v-if="taskNum>0">{{taskNum}}</b><i class="iconfont icon-renwuguanli"></i>
          </router-link>
        </li>
        <li>
          <router-link to="/capital/" :class="isActive('/capital/')?'active':''">
            资金<b class="num" v-if="capitalCount.cash>0">{{capitalCount.cash}}</b><i class="iconfont icon-zijinliushui"></i>
          </router-link>
        </li>
        <li>
          <router-link to="/user/" :class="isActive('/user/')?'active':''">
            用户管理<i class="iconfont icon-iconfontwo"></i>
          </router-link>
        </li>
        <li>
          <router-link to="/increment/integral/" :class="isActive('/increment/')?'active':''">
            积分签到抽奖<i class="iconfont icon-jifen"></i>
          </router-link>
        </li>
        <li>
          <router-link to="/set/" :class="isActive('/set/')?'active':''">
            基本设置<i class="iconfont icon-shezhi"></i>
          </router-link>
        </li>
        <li>
          <router-link to="/active/statistics" :class="isActive('/active/')?'active':''">
            抽奖活动<i class="iconfont icon-shezhi"></i>
          </router-link>
        </li>
        <li>
          <router-link to="/home" :class="$route.path=='/home'?'active':''">
            首页<i class="iconfont icon-shouye"></i>
          </router-link>
        </li>
      </ul>
    </div>
    <div class="disflex navRight">
      <router-view />
    </div>
  </div>
</template>

<script>
  import {
    mapGetters
  } from 'vuex';
  import utils from '@/utils/index';
  import fetch from '@/api/axios';
  export default {
    data() {
      return {
        timer: 0,
        adminLink: utils.handleLocalStorage.get('adminLink'),
      }
    },
    computed: {
      ...mapGetters({
        taskNum: 'taskNum',
        taskCount: 'task',
        capitalCount: 'capital'
      }),
    },
    methods: {
      isActive(path) {
        return this.$route.path.indexOf(path) != -1;
      },
      getCount() { //获取导航栏上个的数字
        let _this = this;
        let count;
        fetch.get('/api/console/system/tips').then((res) => {
          let data = res.data;
          if (data.code == 0) {
            count = data.data;
            if (count) {
              let badge = {
                check_task: count.check_task,
                report: count.report,
                arbitration: count.arbitration,
                user_abnormal: count.user_abnormal,
                cash: count.cash
              };
              _this.$store.commit('updateBadge', badge);
            }

          }
        }).finally(() => {
          clearTimeout(this.timer);
          // 调试其它的，暂时注释
          // _this.timer = setTimeout(()=>{
          // 	_this.getCount();
          // },10000);
        });

      },
      logout() {
        utils.handleLocalStorage.remove('authorized_key');
        utils.handleLocalStorage.remove('name');
        this.$router.replace('/login');
      },
    },
    mounted() {
      this.getCount();
    }
  }
</script>
<style lang="scss" scoped>
  .nav {
    width: 300px;
    height: 100vh;
    overflow-y: auto;
    //box-shadow:0px 0px 10px #e3e3e3;
    border-right: 1px solid #F6F6F6;
    background: #FFF;
    padding-top: 25px;

    &::-webkit-scrollbar {
      display: none
    }

    .logo {
      text-align: center;
      padding: 15px 0;
      cursor: pointer;
      font-size: 22px;
      font-weight: bold;
      -webkit-background-clip: text;
      color: transparent;
      -webkit-text-fill-color: transparent;
      text-fill-color: transparent;

      img {
        width: 32px;
        height: 32px;
        vertical-align: middle;
        margin-right: 10px;
      }
    }

    .adminUser {
      padding: 0 30px;
      margin-top: 35px;
      line-height: 45px;

      .head {
        border-radius: 50%;
        width: 45px;
        height: 45px;
        display: block;
      }

      &>div {
        padding: 0 16px;

        h3 {
          font-weight: normal;
          font-size: 16px;
          line-height: 20px;
        }

        p {
          color: #b3b3b3;
          font-size: 12px;
          line-height: 20px;
          margin-top: 5px;
          cursor: pointer;
        }
      }

      .icon {
        width: 17px;
        height: 17px;
        vertical-align: middle;
      }
    }
  }

  .navRight {
    padding: 30px 35px;
    height: 100vh;
    overflow-y: auto;
    min-width: 1100px;
  }

  .navList {
    padding: 0 25px;
    margin-top: 50px;

    li {
      margin-bottom: 12px;

      a {
        text-decoration: none;
        color: #818181;
        padding: 0 20px;
        font-size: 14px;
        line-height: 50px;
        height: 50px;
        cursor: pointer;
        display: block;
        position: relative;

        i {
          float: right;
          color: #cdcdcd;
          font-size: 15px;
        }

        &.active {
          border-radius: 3px;
          background: linear-gradient(to right, #6eb5ff, #409EFE);
          color: #FFF;

          i {
            color: #FFF;
          }
        }
      }
    }
  }

  .num {
    color: #FFF;
    background: #f56c6c;
    font-weight: normal;
    padding: 0px 8px;
    border-radius: 20px;
    font-size: 13px;
    margin-left: 12px;
    position: relative;
    top: -11px;
    height: 20px;
    display: inline-block;
    line-height: 20px;
  }
</style>
